package minh.bac.wcbrazil2014.adapter;

import java.util.List;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

import minh.bac.wcbrazil2014.R;
import minh.bac.wcbrazil2014.object.FavoriteObj;
import android.content.Context;
import android.media.Image;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;

public class FavoriteListViewAdapter extends ArrayAdapter<FavoriteObj>{

	Context context;
	int resource;
	List<FavoriteObj> objects;
	DisplayImageOptions displayImageOptions;
	public FavoriteListViewAdapter(Context context, int resource,
			List<FavoriteObj> objects, DisplayImageOptions displayImageOptions ) {
		super(context, resource, objects);
		// TODO Auto-generated constructor stub
		this.context = context;
		this.resource = resource;
		this.objects = objects;
		this.displayImageOptions = displayImageOptions;
	}
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder viewHolder ;
		LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		if(convertView == null)
		{
			viewHolder = new ViewHolder();
			convertView = inflater.inflate(resource, parent, false);
			viewHolder.teamImg = (ImageView) convertView.findViewById(R.id.img_team_favorite);
			viewHolder.nameTextView = (TextView) convertView.findViewById(R.id.name_team_favorite);
			viewHolder.rankTextView = (TextView) convertView.findViewById(R.id.rank_team_favorite);					
			//
			convertView.setTag(viewHolder);
		}
		else
			viewHolder = (ViewHolder) convertView.getTag();
		viewHolder.nameTextView.setText(objects.get(position).getFootBallTeamObj().getDoiBong());
		viewHolder.rankTextView.setText("" + objects.get(position).getFootBallTeamObj().getXepHangFiFa());
		ImageLoader.getInstance().displayImage(objects.get(position).getImgLink(), viewHolder.teamImg, displayImageOptions);
			
		return convertView;
	}
	private class ViewHolder{
		TextView nameTextView, rankTextView;
		ImageView teamImg;
		
	}

}
